<?php

use Doraemon\service\TopicActivityAnswer;
use Doraemon\tools\BlockType;

/**
 * 开奖话题动态
 */
class TopicDynamicAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $page = $this->getRequest()->getQuery('page', 1);
        $page = $page ? $page : 1;
        if ($page == 1) {
            $current_time = time();
        } else {
            $current_time = $this->getRequest()->get('current_time', time());
        }
        $result = $this->getTopicAnswer($this->uid, $page, $current_time);
        $result['current_time'] = $current_time;
        $this->setSuccess($result);
    }

    private function getTopicAnswer($uid, $page, $current_time)
    {
        $list = [];
        $isOver = 1;
        $topicId = 1061;
        if ($topicId) {
            list($result, $isOver) = TopicActivityAnswer::getAnswerListByTime323($topicId, $page, $uid, $current_time);
            foreach ($result as $row) {
                if (isset($row['user_info']) && !in_array($row['user_info']['uid'], [11941, 6587838])) {//开奖内容 Feed 去除官方内容
                    $list[] = [
                        'type' => BlockType::TYPE_PHOTO,
                        'photo' => $row,
                    ];
                }
            }
        }
        return ['list' => $list, 'is_over' => $isOver];
    }
}